package gof_003_行为型_Behavioral.gof_004_策略_Strategy.gof_002_Strategy;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamMain {

    //生成学生列表
    public static List<Student> generateStudentList() {
        List<Student> studentList = Stream.of(
                new Student("赵18", 18),
                new Student("钱19", 19),
                new Student("孙20", 20),
                new Student("李21", 21),
                new Student("周22", 22),
                new Student("吴23", 23),
                new Student("郑24", 24),
                new Student("王25", 25)
        ).collect(Collectors.toList());
        return studentList;
    }

    //展示学生列表
    public static void showStudentList(List<Student> studentList) {
        System.out.println("======= 学生列表 =======");
        int index = 0;
        for (Student student : studentList) {
            System.out.println(++index + ".  姓名:" + student.getName() + "\t年龄:" + student.getAge());
        }
    }


    public static void main(String[] args) {
        List<Student> studentList = generateStudentList();

        //策略1
        List<Student> s1 = studentList.stream().filter(i -> i.getAge() > 20).collect(Collectors.toList());
        showStudentList(s1);

        //策略2
        List<Student> s2 = studentList.stream().filter(i -> i.getAge() > 20 && i.getAge() <= 23).collect(Collectors.toList());
        showStudentList(s2);

        //策略3
        List<Student> s3 = studentList.stream().filter(i -> i.getAge() <= 24 && (i.getName().contains("赵") || i.getName().contains("钱"))).collect(Collectors.toList());
        showStudentList(s3);
    }
}
